package com.okaixz.client.utils;

import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.okaixz.web.core.config.SensitiveWordConfig;

import java.util.List;

public class SensitiveWordUtil {
    /**
     * 检测文本中是否包含敏感词
     * @param text 待检测文本
     * @return 是否包含敏感词
     */
    public static boolean contains(String text) {
        SensitiveWordBs sensitiveWordBs = SensitiveWordConfig.SensitiveWordHolder.getSensitiveWordBs();
        return sensitiveWordBs.contains(text);
    }

    /**
     * 获取文本中所有敏感词
     * @param text 待检测文本
     * @return 敏感词列表
     */
    public static List<String> findAll(String text) {
        SensitiveWordBs sensitiveWordBs = SensitiveWordConfig.SensitiveWordHolder.getSensitiveWordBs();
        return sensitiveWordBs.findAll(text);
    }

    /**
     * 替换敏感词（用*替换）
     * @param text 待处理文本
     * @return 替换后的文本
     */
    public static String replace(String text) {
        SensitiveWordBs sensitiveWordBs = SensitiveWordConfig.SensitiveWordHolder.getSensitiveWordBs();
        return sensitiveWordBs.replace(text);
    }


}
